package com.los.rabbitmq.routing;

import com.los.rabbitmq.utils.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @program: rabbitmq
 * @description: 路由模式--发送消息
 * @author: Yujuan
 * @create: 2018-08-02 14:36
 **/
public class Send {
    private static final String EXCHANGE_NAME="los_exchange_direct";

    public static void main(String[] args) throws IOException, TimeoutException {
        //获取一个连接
        Connection connection= ConnectionUtils.getConnection();
        //创建一个通道
        Channel channel=connection.createChannel();
        //绑定到交换机
        channel.exchangeDeclare(EXCHANGE_NAME,"direct");
        String msg="Hello Direct";

        String routingKey="error";
        channel.basicPublish(EXCHANGE_NAME,routingKey,null,msg.getBytes());

        System.out.println("Send:"+msg);
        channel.close();
        connection.close();
    }
}
